package com.zhanglinfeng.api.config;

import feign.RequestTemplate;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import feign.gson.GsonEncoder;

import java.lang.reflect.Type;

/**
 * 替换默认的编码，使用GsonEncoder
 */
public class MyEncoder implements Encoder {

    private GsonEncoder gsonEncoder;

    public MyEncoder() {
        gsonEncoder = new GsonEncoder();
    }

    @Override
    public void encode(Object o, Type type, RequestTemplate requestTemplate) throws EncodeException {
        System.out.println("encode object is class" + o.getClass().getName());
        System.out.println("encode bodyType is class" + type.getClass().getName());
        System.out.println("encode bodyType is value" + type);
        gsonEncoder.encode(o, type, requestTemplate);
    }
}
